#pragma once

#include "winos.h"

_SSL_BEGIN
_SSWINOSL_BEGIN

_SSBASEL_USE_NP

SSWINOS_API bool svr_is_installed(ss_in_ const tchar *service_name, ss_out_ bool &installed);
SSWINOS_API bool svr_install(const tchar *service_name, const tchar *bin_path = NULL, const tchar *display_name = NULL,
	DWORD service_type = SERVICE_WIN32_OWN_PROCESS|SERVICE_INTERACTIVE_PROCESS, DWORD service_start_type = SERVICE_AUTO_START,
	const tchar *dependencies = _T(""), const tchar *start_name = NULL, const tchar *start_pwd = NULL);
SSWINOS_API bool svr_uninstall(const tchar *service_name);

typedef void* service_handle;
SSWINOS_API service_handle svr_ctl_open(const tchar *service_name, DWORD sc_manager_access = SC_MANAGER_ALL_ACCESS,
	DWORD sc_access = SERVICE_ALL_ACCESS);
SSWINOS_API bool svr_ctl_start(service_handle h, DWORD argc, const tchar **argv);
SSWINOS_API bool svr_ctl_query_status(ss_in_ service_handle h, ss_out_ SERVICE_STATUS &status);
SSWINOS_API bool svr_ctl_control(service_handle h, DWORD control_code);
SSWINOS_API bool svr_ctl_stop(service_handle h);

class service_host_interface
{
public:
	virtual void main_proc() = 0;
	virtual DWORD get_control_accepte_code() = 0;

public:
	virtual void on_control(DWORD ctl_code) = 0;
};

SSWINOS_API bool svr_host_start(service_host_interface *host);

// CANT WORK ON Win8, I DONT KNOW WHY
SSWINOS_API HANDLE svr_host_before_interactive_call();
SSWINOS_API bool svr_host_after_interactive_call(HANDLE h);

_SSWINOSL_END
_SSL_END

